//
//  GoodsTableViewCell.swift
//  ShareUmbrella
//
//  Created by keng fu on 2017/8/16.
//  Copyright © 2017年 尧尚信息科技. All rights reserved.
//

import UIKit
import YSKit

class GoodsTableViewCell: YSBaseTableViewCell {
    
    var lblNickName = UILabel()
    var lblTime = UILabel()
    var lblGoodsName = UILabel()
    
    var imgGoods = UIImageView()
    var btnPoint = UIButton()
    var btnDelete = UIButton()
    
    var model: GoodsModel!
    
    override func setup() {
        super.setup()
        // Initialization code
        
        self.backgroundColor = UIColor(colorLiteralRed: 0.9, green: 0.9, blue: 0.9, alpha: 1)
        
        lblNickName.ys.customize { (view) in
            view.font = UIFont.systemFont(ofSize: 13.0)
            view.textColor = .gray
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(self.snp.top).offset(3)
                make.leading.equalTo(self.snp.leading).offset(10)
            })
        }
        
        



        
        btnDelete.ys.customize { (view) in
            self.addSubview(view)
            view.setImage(UIImage(named: "删除icon"), for: .normal)
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(self.snp.top).offset(3)
                make.trailing.equalTo(self.snp.trailing).offset(-10)
            })
        }
        
        let _ = UIView(frame: .zero).ys.customize { (view) in
            self.addSubview(view)
            view.backgroundColor = UIColor(colorLiteralRed: 0.7, green: 0.7, blue: 0.7, alpha: 1)
            view.snp.makeConstraints({ (make) in
                make.bottom.trailing.leading.equalTo(self)
                make.height.equalTo(1)
            })
        }
        
        imgGoods.ys.customize { (view) in
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.bottom.equalTo(self.snp.bottom).offset(-15)
                make.width.height.equalTo(60)
                make.leading.equalTo(10)
            })
        }
        
        
        btnPoint.ys.customize { (view) in
            view.setBackgroundImage(UIImage(named: "价钱框"), for: .normal)
            view.setTitleColor(UIColor.white, for: .normal)
            view.titleLabel?.font = UIFont.systemFont(ofSize: 15)
            
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.centerY.equalTo(imgGoods.snp.centerY)
                make.trailing.equalTo(self.snp.trailing).offset(-10)
                make.height.equalTo(20)
                make.width.equalTo(50)
            })
        }
        
        
        lblGoodsName.ys.customize { (view) in
            view.font = UIFont.systemFont(ofSize: 15)
            view.numberOfLines = 2
            view.adjustsFontSizeToFitWidth = true
            
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.top.equalTo(imgGoods.snp.top)
                make.leading.equalTo(imgGoods.snp.trailing).offset(20)
                make.trailing.equalTo(btnPoint.snp.leading).offset(20)
            })
        }
        
        
        lblTime.ys.customize { (view) in
            view.font = UIFont.systemFont(ofSize: 13)
            self.addSubview(view)
            view.snp.makeConstraints({ (make) in
                make.bottom.equalTo(imgGoods.snp.bottom)
                make.leading.equalTo(lblGoodsName.snp.leading)
            })
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    func updateUI(goods: GoodsModel){
        
        self.lblNickName.text = goods.userName
        self.lblTime.text = goods.goodsTime
        self.lblGoodsName.text = goods.goodsName
        self.imgGoods.image = goods.goodsImage
        self.btnPoint.setTitle(String(goods.goodsPoint), for: .normal)
        
    }
}
